from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class ArticePageNum(PageNumberPagination):

    page_size = 5
    page_size_query_param='pagesize'
    page_query_param = "pagenum"  # 前端传入第几页
    max_page_size = 10


    def get_paginated_response(self, data):
        print(data)
        return Response(
            {
                "status":0,
                "message": "获取文章列表成功！",
                "data":data,
                "total": self.page.paginator.count
            })

    # {
    #     "status": 0,
    #     "message": "获取文章列表成功！",
    #     "data": [
    #         {
    #             "Id": 1,
    #             "title": "abab",
    #             "pub_date": "2020-01-03 12:19:57.690",
    #             "state": "已发布",
    #             "cate_name": "最新"
    #         },
    #         {
    #             "Id": 2,
    #             "title": "666",
    #             "pub_date": "2020-01-03 12:20:19.817",
    #             "state": "已发布",
    #             "cate_name": "股市"
    #         }
    #     ],
    #     "total": 5
#     # }
#
# class ArticePageNum2(PageNumberPagination):
#
#     page_size = 5
#     page_size_query_param='pagesize'
#     max_page_size = 10
#
#
#     def get_paginated_response(self, data):
#         print(data)
#         return Response(
#             {
#                 "status":0,
#                 "message": "获取文章列表成功！",
#                 "data":data,
#                 "total": self.page.paginator.count
#             })